package br.com.estudosjsf.leilao.domain;

import java.io.Serializable;

import javax.enterprise.context.Dependent;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;

@Dependent
@Entity
public class Avaliacao implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	@Id
	@GeneratedValue(generator="avaliacao_id_seq", strategy=GenerationType.SEQUENCE)
	@SequenceGenerator(name="avaliacao_id_seq",sequenceName="avaliacao_id_seq", allocationSize=1)
	private Integer id;
	private String nome;
	private String texto;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_modelo")
	private Modelo modelo;
	

	public String getTexto() {
		return texto;
	}
	public void setTexto(String texto) {
		this.texto = texto;
	}
	public Modelo getModelo() {
		return modelo;
	}
	public void setModelo(Modelo modelo) {
		this.modelo = modelo;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	
	@Override
	public int hashCode() {
		return getNome().length() * 8;
	}
	
	@Override
	public boolean equals(Object obj) {
		if((obj instanceof Avaliacao) && ((Avaliacao)obj).getNome().equals(this.getNome())){
			return true;
		} else{
			return false;
		}
	}
}